package org.jeecg.modules.xxgx.kpzdgl.entity;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;
import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.DateUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @Description: 开票终端
 * @Author: jeecg-boot
 * @Date:   2023-08-19
 * @Version: V1.0
 */
@Data
@TableName("cs_xx_kpzd")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="cs_xx_kpzd对象", description="开票终端")
public class CsXxKpzd implements Serializable {
    private static final long serialVersionUID = 1L;

	/**编号*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "编号")
    private String id;
	/**创建人*/
    @ApiModelProperty(value = "创建人")
    private String createBy;
	/**创建日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "创建日期")
    private Date createTime;
	/**更新人*/
    @ApiModelProperty(value = "更新人")
    private String updateBy;
	/**更新日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "更新日期")
    private Date updateTime;
	/**所属部门*/
    @ApiModelProperty(value = "所属部门")
    private String sysOrgCode;
	/**租户编号*/
	@Excel(name = "租户编号", width = 15)
    @ApiModelProperty(value = "租户编号")
    private Integer tenantId;
	/**企业主键*/
	@Excel(name = "企业主键", width = 15)
    @ApiModelProperty(value = "企业主键")
    private String companyId;
	/**终端代码*/
	@Excel(name = "终端代码", width = 15)
    @ApiModelProperty(value = "终端代码")
    private String zddm;
	/**终端名称*/
	@Excel(name = "终端名称", width = 15)
    @ApiModelProperty(value = "终端名称")
    private String zdmc;
	/**终端类型*/
	@Excel(name = "终端类型", width = 15, dicCode = "kpzdlx")
	@Dict(dicCode = "kpzdlx")
    @ApiModelProperty(value = "终端类型")
    private String zdlx;
	/**服务器*/
	@Excel(name = "服务器", width = 15)
    @ApiModelProperty(value = "服务器")
    private String fwqid;
	/**开票模式*/
	@Excel(name = "开票模式", width = 15, dicCode = "kpzdms")
	@Dict(dicCode = "kpzdms")
    @ApiModelProperty(value = "开票模式")
    private String kpms;
	/**特定业务*/
	@Excel(name = "特定业务", width = 15)
    @ApiModelProperty(value = "特定业务")
    private String tdyw;
	/**发票类型代码*/
	@Excel(name = "发票类型代码", width = 15)
    @ApiModelProperty(value = "发票类型代码")
    private String fplxdm;
	/**企业代码*/
	@Excel(name = "企业代码", width = 15)
    @ApiModelProperty(value = "企业代码")
    private String nsrdm;
	/**企业税号*/
	@Excel(name = "企业税号", width = 15)
    @ApiModelProperty(value = "企业税号")
    private String nsrsbh;
	/**企业名称*/
	@Excel(name = "企业名称", width = 15)
    @ApiModelProperty(value = "企业名称")
    private String nsrmc;
	/**销方银行*/
	@Excel(name = "销方银行", width = 15)
    @ApiModelProperty(value = "销方银行")
    private String xfyh;
	/**银行账号*/
	@Excel(name = "银行账号", width = 15)
    @ApiModelProperty(value = "银行账号")
    private String xfyhzh;
	/**地址*/
	@Excel(name = "地址", width = 15)
    @ApiModelProperty(value = "地址")
    private String xfdz;
	/**电话*/
	@Excel(name = "电话", width = 15)
    @ApiModelProperty(value = "电话")
    private String xfdh;
	/**开票人*/
	@Excel(name = "开票人", width = 15)
    @ApiModelProperty(value = "开票人")
    private String kpr;
	/**收款人*/
	@Excel(name = "收款人", width = 15)
    @ApiModelProperty(value = "收款人")
    private String skr;
	/**复核人*/
	@Excel(name = "复核人", width = 15)
    @ApiModelProperty(value = "复核人")
    private String fhr;
	/**局端账号*/
	@Excel(name = "局端账号", width = 15)
    @ApiModelProperty(value = "局端账号")
    private String dzswjzh;
	/**登录密码*/
	@Excel(name = "登录密码", width = 15)
    @ApiModelProperty(value = "登录密码")
    private String dzswjmm;
	/**登录角色*/
	@Excel(name = "登录角色", width = 15)
    @ApiModelProperty(value = "登录角色")
    private String dljs;
	/**手机号*/
	@Excel(name = "手机号", width = 15)
    @ApiModelProperty(value = "手机号")
    private String sjh;
	/**身份证号*/
	@Excel(name = "身份证号", width = 15)
    @ApiModelProperty(value = "身份证号")
    private String sfzh;
	/**角色密码*/
	@Excel(name = "角色密码", width = 15)
    @ApiModelProperty(value = "角色密码")
    private String dljsmm;
	/**扫码频率*/
	@Excel(name = "扫码频率", width = 15)
    @ApiModelProperty(value = "扫码频率")
    private Integer smpl;
	/**最近扫码时间*/
	@Excel(name = "最近扫码时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "最近扫码时间")
    private Date zjsmsj;

    /**下次认证时间*/
    @Excel(name = "下次认证时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "下次认证时间")
    @TableField(exist = false)
    private Date xcrzsj;

    /**登录时间*/
    @Excel(name = "登录时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "登录时间")
    private Date dlsj;
    /**默认终端：是、否*/
    @Excel(name = "默认终端：是、否", width = 15)
    @ApiModelProperty(value = "默认终端：是、否")
    private String ismrzd;


    public Date getXcrzsj() {
        //计算下次扫码时间
        if(this.getZjsmsj() == null || this.getSmpl() == null || this.getSmpl() == 0){
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(this.getZjsmsj());
        calendar.add(Calendar.HOUR, this.getSmpl());
        return calendar.getTime();
    }

    @Excel(name = "认证结果：已认证；认证失效", width = 15)
    @ApiModelProperty(value = "认证结果：已认证；认证失效")
    private String rzjg;

    @Excel(name = "在线状态:在线；离线", width = 15)
    @ApiModelProperty(value = "在线状态:在线；离线")
    private String zxzt;

    public String getRzjg() {
        String rzjg = this.rzjg;
        if(StringUtils.isEmpty(rzjg)) {
            //计算下次扫码时间
            Date xcrzsj = getXcrzsj();
            Date currentTime = new Date();
            if (xcrzsj != null) {
                if (DateUtils.compare(xcrzsj, currentTime) > 0) {
                    rzjg = "认证失效";
                } else {
                    rzjg = "已认证";
                }
            }
        }
        return rzjg;
    }
}
